
package harlequin;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class ShowDelete extends AddEditDeleteShow{


    private String deletequery = "delete from play where title = ? and dateTimeslot = ?";
    
    public ShowDelete(Connection connector){
        this.connector = connector;
        this.setLocationByPlatform(rootPaneCheckingEnabled);
        this.setTitle("Delete Show");
          //initializeDateTimeslotCombo();
        
        initComponents();
        
       // initializeTitleCombo();
  
        
    }


    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        tTitle = new javax.swing.JTextField();
        bDeleteShow = new javax.swing.JButton();
        bBack = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tPrice = new javax.swing.JTextField();
        tSlot = new javax.swing.JTextField();
        tDateTimeslot = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel2.setText("Date-Timeslot:");

        jLabel1.setText("Title:");

        tTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tTitleActionPerformed(evt);
            }
        });

        bDeleteShow.setText("Delete");
        bDeleteShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bDeleteShowActionPerformed(evt);
            }
        });

        bBack.setText("Back");
        bBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBackActionPerformed(evt);
            }
        });

        jLabel4.setText("Slot:");

        jLabel5.setText("Price:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tSlot, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tPrice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                        .addComponent(tTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tDateTimeslot, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
                    .addComponent(bDeleteShow, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bBack, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tDateTimeslot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tSlot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(128, 128, 128)
                .addComponent(bDeleteShow)
                .addGap(7, 7, 7)
                .addComponent(bBack)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void bDeleteShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeleteShowActionPerformed
  
    try {
            title = tTitle.getText();
            dateTimeslot = tDateTimeslot.getText();
            
            if(title.isEmpty() && dateTimeslot.isEmpty() )
             JOptionPane.showMessageDialog(null, "Deleting failed! \nPlease input all empty fields.");
            else if(title.isEmpty())
             JOptionPane.showMessageDialog(null, "Deleting failed!\n Please specify which Show Title");
            else if(dateTimeslot.isEmpty())
             JOptionPane.showMessageDialog(null, "Deleting failed!\n Please specify Date of show");
            else if (!DateExists(dateTimeslot))
                JOptionPane.showMessageDialog(null, "Deleting failed!\n Show with that date does not exsists");
            else if (dateTimeslot.length() < 18)
                JOptionPane.showMessageDialog(null, "Deleting failed!\n Date format should be: \n mm/dd/yy");
            else {
            java.sql.PreparedStatement preparedStatement = connector.prepareStatement(deletequery);
            preparedStatement.setString(1, title);
            preparedStatement.setString(2, dateTimeslot);
            preparedStatement.execute();
            JOptionPane.showMessageDialog(null, "Delete Success!");
            this.dispose();

}
        } catch (SQLException ex) {
            Logger.getLogger(ShowDelete.class.getName()).log(Level.SEVERE, null, ex);
        }
   
}//GEN-LAST:event_bDeleteShowActionPerformed

private void bBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBackActionPerformed

    this.dispose();
   
}//GEN-LAST:event_bBackActionPerformed

private void tTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tTitleActionPerformed
  
}//GEN-LAST:event_tTitleActionPerformed

private void initializeDateTimeslotCombo(String title){
try {
  Statement stmt = connector.createStatement();
  ResultSet rs = stmt.executeQuery("Select dateTimeslot from play where title = \"" + title + "\"");
  while(rs.next()){
   // cDateTimeslot.addItem(rs.getString("dateTimeslot"));
  }
  } catch (SQLException ex) {
      Logger.getLogger(AttendanceDLSU.class.getName()).log(Level.SEVERE, null, ex);
  }   
} 

private void initializeTitleCombo(){
try {
  Statement stmt = connector.createStatement();
  ResultSet rs = stmt.executeQuery("Select * from play");
  while(rs.next()){
   // cTitle.addItem(rs.getString("title"));
  }
  } catch (SQLException ex) {
      Logger.getLogger(HomePage.class.getName()).log(Level.SEVERE, null, ex);
  }   
}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBack;
    private javax.swing.JButton bDeleteShow;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField tDateTimeslot;
    private javax.swing.JTextField tPrice;
    private javax.swing.JTextField tSlot;
    private javax.swing.JTextField tTitle;
    // End of variables declaration//GEN-END:variables
}
